package com.example.xuwsh.myBatisPlus.core.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.example.xuwsh.myBatisPlus.core.abstracts.JuXiLambdaWrapper;

import java.util.Collection;

/**
 * @Author: xuwsh
 * @Date: 2023/09/20/15:14
 * @Description: 对LambdaQueryWrapper 进一层封装，将传入的值进行判断是否为空，如果为空不需要查询
 */
public class JuXiLambdaQueryWrapper<T> extends JuXiLambdaWrapper<JuXiLambdaQueryWrapper<T>, T> {

    //1、new 对象，
    //2、调用方法
    //2.1、相等、不等、模糊、In、 notIn、isNotNull


//    public QueryWrapper<T> selectList(){
//        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByAsc()
//        return queryWrapper;
//    }


    /**
     * 使用eq的时候，值不为空
     *
     * @param column
     * @param val
     * @return
     */
    @Override
    public JuXiLambdaQueryWrapper<T> eqIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.eq(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> neIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.ne(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> gtIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.gt(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> geIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.ge(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> ltIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.lt(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> leIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.le(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> betweenIfPresent(SFunction<T, ?> column, Object val, Object val1) {
        if (ObjectUtil.isNotEmpty(val) && ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaQueryWrapper<T>) super.between(column, val, val1);
        }
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) ge(column, val);
        }
        if (ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaQueryWrapper<T>) le(column, val1);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> notBetweenIfPresent(SFunction<T, ?> column, Object val, Object val1) {
        if (ObjectUtil.isNotEmpty(val) && ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaQueryWrapper<T>) super.notBetween(column, val, val1);
        }
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) lt(column, val);
        }
        if (ObjectUtil.isNotEmpty(val1)) {
            return (JuXiLambdaQueryWrapper<T>) gt(column, val1);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> likeIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.like(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> noLikeIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.notLike(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> likeLeftIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.likeLeft(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> notLikeLeftIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.notLikeLeft(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> likeRightIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.likeRight(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> notLikeRightIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.notLikeRight(column, val);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> isNullIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.isNull(column);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> isNotNullIfPresent(SFunction<T, ?> column, Object val) {
        if (ObjectUtil.isNotEmpty(val)) {
            return (JuXiLambdaQueryWrapper<T>) super.isNotNull(column);
        }
        return this;
    }


    @Override
    public JuXiLambdaQueryWrapper<T> inListIfPresent(SFunction<T, ?> column, Collection<?> coll) {
        if (CollectionUtil.isNotEmpty(coll)) {
            return (JuXiLambdaQueryWrapper<T>) super.in(column, coll);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> notInListIfPresent(SFunction<T, ?> column, Collection<?> coll) {
        if (CollectionUtil.isNotEmpty(coll)) {
            return (JuXiLambdaQueryWrapper<T>) super.notIn(column, coll);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> inArrayIfPresent(SFunction<T, ?> column, Object... values) {
        if (ObjectUtil.isAllNotEmpty(values)) {
            return (JuXiLambdaQueryWrapper<T>) super.in(column, values);
        }
        return this;
    }

    @Override
    public JuXiLambdaQueryWrapper<T> notInArrayIfPresent(SFunction<T, ?> column, Object... values) {
        if (ObjectUtil.isAllNotEmpty(values)) {
            return (JuXiLambdaQueryWrapper<T>) super.notIn(column, values);
        }
        return this;
    }


    @Override
    protected JuXiLambdaWrapper<JuXiLambdaQueryWrapper<T>, T> instance() {
        return null;
    }
}

